package cn.ibizlab.odoo.core.odoo_account.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line;
import cn.ibizlab.odoo.core.odoo_account.domain.Account_bank_statement_line;
import cn.ibizlab.odoo.core.odoo_account.filter.Account_bank_statement_lineSearchContext;
import cn.ibizlab.odoo.core.odoo_account.service.IAccount_bank_statement_lineService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[银行对账单明细] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Account_bank_statement_lineServiceImpl implements IAccount_bank_statement_lineService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iaccount_bank_statement_lineClientService account_bank_statement_lineClientService;

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //account_bank_statement_lineClientService.removeBatch(account_bank_statement_lines) ;

    }

    @Override
    public void createBatch(List<Account_bank_statement_line> account_bank_statement_lines, int batchSize) {

                        //account_bank_statement_lineClientService.createBatch(account_bank_statement_lines,batchSize) ;

    }

    @Override
    public boolean update(Account_bank_statement_line account_bank_statement_line) {
        boolean bOk = false ;
        Iaccount_bank_statement_line clientModel = this.convert2Model(account_bank_statement_line,null);
        account_bank_statement_lineClientService.update(clientModel) ;
        this.convert2Domain(clientModel,account_bank_statement_line) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iaccount_bank_statement_line clientModel = account_bank_statement_lineClientService.createModel();
        clientModel.setId(id);
        account_bank_statement_lineClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean create(Account_bank_statement_line account_bank_statement_line) {
        boolean bOk = false ;
        Iaccount_bank_statement_line clientModel = this.convert2Model(account_bank_statement_line,null);
        account_bank_statement_lineClientService.create(clientModel) ;
        this.convert2Domain(clientModel,account_bank_statement_line);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void updateBatch(List<Account_bank_statement_line> account_bank_statement_lines, int batchSize) {

        //account_bank_statement_lineClientService.updateBatch(account_bank_statement_lines,batchSize) ;

    }

    @Override
    public Account_bank_statement_line get(Integer id) {
        Iaccount_bank_statement_line clientModel = account_bank_statement_lineClientService.createModel();
        clientModel.setId(id);
        account_bank_statement_lineClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Account_bank_statement_line get(Account_bank_statement_line account_bank_statement_line) {
        Account_bank_statement_line retaccount_bank_statement_line = this.get(account_bank_statement_line.getId()) ;
    	BeanCopier copier=BeanCopier.create(retaccount_bank_statement_line.getClass(), account_bank_statement_line.getClass(), false);
        copier.copy(retaccount_bank_statement_line, account_bank_statement_line, null);
        return account_bank_statement_line ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Account_bank_statement_line> searchDefault(Account_bank_statement_lineSearchContext context) {
        List<Account_bank_statement_line> list = new ArrayList<Account_bank_statement_line>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line> clientModelList = account_bank_statement_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_line>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据科目查询
     */
    @Override
    public Page<Account_bank_statement_line> selectByOdoo_account(Integer id){
        Account_bank_statement_lineSearchContext context = new Account_bank_statement_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement_line> list = new ArrayList<Account_bank_statement_line>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line> clientModelList = account_bank_statement_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据银行对账单查询
     */
    @Override
    public Page<Account_bank_statement_line> selectByOdoo_statement(Integer id){
        Account_bank_statement_lineSearchContext context = new Account_bank_statement_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement_line> list = new ArrayList<Account_bank_statement_line>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line> clientModelList = account_bank_statement_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据日记账查询
     */
    @Override
    public Page<Account_bank_statement_line> selectByOdoo_journal(Integer id){
        Account_bank_statement_lineSearchContext context = new Account_bank_statement_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement_line> list = new ArrayList<Account_bank_statement_line>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line> clientModelList = account_bank_statement_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据公司查询
     */
    @Override
    public Page<Account_bank_statement_line> selectByOdoo_company(Integer id){
        Account_bank_statement_lineSearchContext context = new Account_bank_statement_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement_line> list = new ArrayList<Account_bank_statement_line>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line> clientModelList = account_bank_statement_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据币种查询
     */
    @Override
    public Page<Account_bank_statement_line> selectByOdoo_currency(Integer id){
        Account_bank_statement_lineSearchContext context = new Account_bank_statement_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement_line> list = new ArrayList<Account_bank_statement_line>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line> clientModelList = account_bank_statement_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据银行账户查询
     */
    @Override
    public Page<Account_bank_statement_line> selectByOdoo_bank_account(Integer id){
        Account_bank_statement_lineSearchContext context = new Account_bank_statement_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement_line> list = new ArrayList<Account_bank_statement_line>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line> clientModelList = account_bank_statement_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据联系人查询
     */
    @Override
    public Page<Account_bank_statement_line> selectByOdoo_partner(Integer id){
        Account_bank_statement_lineSearchContext context = new Account_bank_statement_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement_line> list = new ArrayList<Account_bank_statement_line>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line> clientModelList = account_bank_statement_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_bank_statement_line> selectByOdoo_create(Integer id){
        Account_bank_statement_lineSearchContext context = new Account_bank_statement_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement_line> list = new ArrayList<Account_bank_statement_line>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line> clientModelList = account_bank_statement_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_bank_statement_line> selectByOdoo_write(Integer id){
        Account_bank_statement_lineSearchContext context = new Account_bank_statement_lineSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement_line> list = new ArrayList<Account_bank_statement_line>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line> clientModelList = account_bank_statement_lineClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_line clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_line>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Iaccount_bank_statement_line convert2Model(Account_bank_statement_line domain , Iaccount_bank_statement_line model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = account_bank_statement_lineClientService.createModel() ;
        }

         if(domain.getPartner_nameDirtyFlag())
            model.setPartner_name(domain.getPartner_name());
         if(domain.getSequenceDirtyFlag())
            model.setSequence(domain.getSequence());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getAmountDirtyFlag())
            model.setAmount(domain.getAmount());
         if(domain.getAccount_numberDirtyFlag())
            model.setAccount_number(domain.getAccount_number());
         if(domain.getRefDirtyFlag())
            model.setRef(domain.getRef());
         if(domain.getNoteDirtyFlag())
            model.setNote(domain.getNote());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getJournal_entry_idsDirtyFlag())
            model.setJournal_entry_ids(domain.getJournal_entry_ids());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getMove_nameDirtyFlag())
            model.setMove_name(domain.getMove_name());
         if(domain.getUnique_import_idDirtyFlag())
            model.setUnique_import_id(domain.getUnique_import_id());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getDateDirtyFlag())
            model.setDate(domain.getDate());
         if(domain.getPos_statement_idDirtyFlag())
            model.setPos_statement_id(domain.getPos_statement_id());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getAmount_currencyDirtyFlag())
            model.setAmount_currency(domain.getAmount_currency());
         if(domain.getCompany_id_textDirtyFlag())
            model.setCompany_id_text(domain.getCompany_id_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getJournal_id_textDirtyFlag())
            model.setJournal_id_text(domain.getJournal_id_text());
         if(domain.getStateDirtyFlag())
            model.setState(domain.getState());
         if(domain.getPartner_id_textDirtyFlag())
            model.setPartner_id_text(domain.getPartner_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getJournal_currency_idDirtyFlag())
            model.setJournal_currency_id(domain.getJournal_currency_id());
         if(domain.getCurrency_id_textDirtyFlag())
            model.setCurrency_id_text(domain.getCurrency_id_text());
         if(domain.getStatement_id_textDirtyFlag())
            model.setStatement_id_text(domain.getStatement_id_text());
         if(domain.getAccount_id_textDirtyFlag())
            model.setAccount_id_text(domain.getAccount_id_text());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getAccount_idDirtyFlag())
            model.setAccount_id(domain.getAccount_id());
         if(domain.getCompany_idDirtyFlag())
            model.setCompany_id(domain.getCompany_id());
         if(domain.getCurrency_idDirtyFlag())
            model.setCurrency_id(domain.getCurrency_id());
         if(domain.getPartner_idDirtyFlag())
            model.setPartner_id(domain.getPartner_id());
         if(domain.getBank_account_idDirtyFlag())
            model.setBank_account_id(domain.getBank_account_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getJournal_idDirtyFlag())
            model.setJournal_id(domain.getJournal_id());
         if(domain.getStatement_idDirtyFlag())
            model.setStatement_id(domain.getStatement_id());
        return model ;
    }

    public Account_bank_statement_line convert2Domain( Iaccount_bank_statement_line model ,Account_bank_statement_line domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Account_bank_statement_line();
        }

        if(model.getPartner_nameDirtyFlag())
            domain.setPartner_name(model.getPartner_name());
        if(model.getSequenceDirtyFlag())
            domain.setSequence(model.getSequence());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getAmountDirtyFlag())
            domain.setAmount(model.getAmount());
        if(model.getAccount_numberDirtyFlag())
            domain.setAccount_number(model.getAccount_number());
        if(model.getRefDirtyFlag())
            domain.setRef(model.getRef());
        if(model.getNoteDirtyFlag())
            domain.setNote(model.getNote());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getJournal_entry_idsDirtyFlag())
            domain.setJournal_entry_ids(model.getJournal_entry_ids());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getMove_nameDirtyFlag())
            domain.setMove_name(model.getMove_name());
        if(model.getUnique_import_idDirtyFlag())
            domain.setUnique_import_id(model.getUnique_import_id());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getDateDirtyFlag())
            domain.setDate(model.getDate());
        if(model.getPos_statement_idDirtyFlag())
            domain.setPos_statement_id(model.getPos_statement_id());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getAmount_currencyDirtyFlag())
            domain.setAmount_currency(model.getAmount_currency());
        if(model.getCompany_id_textDirtyFlag())
            domain.setCompany_id_text(model.getCompany_id_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getJournal_id_textDirtyFlag())
            domain.setJournal_id_text(model.getJournal_id_text());
        if(model.getStateDirtyFlag())
            domain.setState(model.getState());
        if(model.getPartner_id_textDirtyFlag())
            domain.setPartner_id_text(model.getPartner_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getJournal_currency_idDirtyFlag())
            domain.setJournal_currency_id(model.getJournal_currency_id());
        if(model.getCurrency_id_textDirtyFlag())
            domain.setCurrency_id_text(model.getCurrency_id_text());
        if(model.getStatement_id_textDirtyFlag())
            domain.setStatement_id_text(model.getStatement_id_text());
        if(model.getAccount_id_textDirtyFlag())
            domain.setAccount_id_text(model.getAccount_id_text());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getAccount_idDirtyFlag())
            domain.setAccount_id(model.getAccount_id());
        if(model.getCompany_idDirtyFlag())
            domain.setCompany_id(model.getCompany_id());
        if(model.getCurrency_idDirtyFlag())
            domain.setCurrency_id(model.getCurrency_id());
        if(model.getPartner_idDirtyFlag())
            domain.setPartner_id(model.getPartner_id());
        if(model.getBank_account_idDirtyFlag())
            domain.setBank_account_id(model.getBank_account_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getJournal_idDirtyFlag())
            domain.setJournal_id(model.getJournal_id());
        if(model.getStatement_idDirtyFlag())
            domain.setStatement_id(model.getStatement_id());
        return domain ;
    }


}
